﻿#ifndef _RTM_POSE_TUILS_H_
#define _RTM_POSE_TUILS_H_

#include "opencv2/opencv.hpp"

const std::vector<float> IMAGE_MEAN{103.53, 116.28, 123.675};
const std::vector<float> IMAGE_STD{57.375, 57.12, 58.395};

// 判断检测框是否有效
struct DetectBox
{
    /* data */
    int left;
    int top;
    int right;
    int bottom;
    float score;
    int label;

    DetectBox()
    {
        left = -1;
        top = -1;
        right = -1;
        bottom = -1;
        score = -1.0;
        label = -1;
    }
    bool IsValid() const
    {
        return left != -1 && top != -1 && right != -1 && bottom != -1 && score != -1.0 && label != -1;
    }
};

static bool BoxCompare(const DetectBox &a, const DetectBox &b)
{
    return a.score > b.score;
}

struct PosePoint
{
    int x;
    int y;
    float score;

    PosePoint()
    {
        x = 0;
        y = 0;
        score = 0.0;
    }
};

typedef PosePoint Vector2D;

class RTMPose_Utils
{
private:
    /* data */
public:
    RTMPose_Utils();

    virtual ~RTMPose_Utils();

public:
    static cv::Mat GetAffineTransform(float center_x, float center_y,
                                      float scale_width, float scale_height,
                                      int output_image_width, int output_image_height,
                                      bool inverse = false);

    static float LetterBoxImage(const cv::Mat &image,
                                cv::Mat &out_image,
                                const cv::Size &new_shape = cv::Size(640, 640),
                                int stride = 32,
                                const cv::Scalar &color = cv::Scalar(114, 114, 114),
                                bool fixed_shape = false,
                                bool scale_up = true);
};

#endif // !_RTM_POSE_TUILS_H_